package gimreader;

import java.awt.List;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import javafx.scene.Node;


/**
 * GimModel is a TreeTableModel representing a hierarchical GIM Jobs content.
 *
 * @version %I% %G%
 *
 * @author Pavel Iusim
 */

public class GimModel extends AbstractTreeTableModel implements TreeTableModel {

    // Names of the columns.
    static protected String[]  cNames = {"Action", "Start Time", "End Time", "Duration", "Records", "-Comment-"};

//     Types of the columns.
//     Не понятно нахера это надо....
    static protected Class[]  cTypes = {TreeTableModel.class, String.class, String.class, String.class, String.class, String.class}; 
//Date.class, Date.class, Integer.class, Integer.class};

    public GimModel(Object root) {
        
        // КАК??? Сюда надо передать Дерево джобов с контентом которое должно собраться в Worker
        
	//super(   new FileNode(new File(File.separator))   );
        super (root);
    }

    //
    // Some convenience methods.
    //

//    protected File getFile(Object node) {
//        //  TODO bla bla bla
//        //System.out.println("gtFile NODE: " + node.toString());        
//        FileNode fileNode = ((FileNode)node);
//	return fileNode.getFile();
//    }

    protected Object[] getChildren(Object node) {
        TreeNode treenode = ((TreeNode)node);
	return treenode.getChildren();
    }

    //
    // The TreeModel interface
    //

    @Override
    public int getChildCount(Object node) {
        Object[] children = getChildren(node);
	return (children == null) ? 0 : children.length;
    }

    @Override
    public Object getChild(Object node, int i) {
        TreeNode treenode = (TreeNode) node;
        
        
        return getChildren(treenode)[i];
    }

    // The superclass's implementation would work, but this is more efficient.
    @Override
    public boolean isLeaf(Object node) {
        TreeNode treenode = (TreeNode) node;
        return treenode.isLeaf(); 
    }

    //
    //  The TreeTableNode interface.
    //

    @Override
    public int getColumnCount() {
	return cNames.length;
    }

    @Override
    public String getColumnName(int column) {
	return cNames[column];
    }

    @Override
    public Class getColumnClass(int column) {
    	return cTypes[column];
    }

    @Override
    public Object getValueAt(Object node, int column) {
        TreeNode tn = (TreeNode) node;
        
        JobEntries JE = (JobEntries) tn.data;

        try {
	    switch(column) {
	    case 0:
		return JE.action;
	    case 1:
                return JE.GetStart()>=0 ? new Date(JE.GetStart()) : "" ;
		//return file.isFile() ? new Integer((int)file.length()) : "-/-/-";
	    case 2:
                //return JE.GetEnd();
		return JE.GetEnd()>=0 ?  new Date(JE.GetEnd()) : "";
	    case 3:
                return JE.GetNiceDuration();
		//return new Date(file.lastModified());
            case 4: 
                return JE.GetRows();
            case 5: 
                return JE.action==2 ? JE.custom1 : JE.GetComment();
                // TODO return source if ExtractStep
	    }
	}
	catch  (SecurityException se) { }

	return null;
    }
}

